package org.zsk.cs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zsk.cs.domain.po.IdentityAuth;
import org.zsk.cs.domain.po.User;
import org.zsk.cs.domain.vo.IdentityAuthVo;
import org.zsk.cs.domain.vo.RoleVo;
import org.zsk.cs.domain.vo.UserVo;
import org.zsk.cs.response.ResultBody;
import org.zsk.cs.service.IdentityAuthService;
import org.zsk.cs.util.UserUtils;
import org.zsk.fastdev.assign.Assign;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 社区身份认证 controller
 * </p>
 *
 * @author zsk
 * @version 1.0
 * Created on 2020/03/29
 */
@RestController
@RequestMapping("/identityauth")
public class IdentityAuthController {

    private final IdentityAuthService identityAuthService;
    private final Assign assign;

    @Autowired
    public IdentityAuthController(IdentityAuthService identityAuthService, Assign assign) {
        this.identityAuthService = identityAuthService;
        this.assign = assign;
    }

    @PostMapping("/a")
    public ResultBody add(@RequestBody IdentityAuthVo identityAuthVo) throws Exception {
        IdentityAuth identityAuth=new IdentityAuth();
        assign.assign(identityAuthVo,identityAuth);
        identityAuthService.save(identityAuth);
        return ResultBody.success();
    }

    @PutMapping("/u")
    public ResultBody update(@RequestBody IdentityAuthVo identityAuthVo) throws Exception {
        IdentityAuth identityAuth=new IdentityAuth();
        assign.assign(identityAuthVo,identityAuth);
        identityAuthService.updateById(identityAuth);
        return ResultBody.success();
    }

    @DeleteMapping("/d/{ids}")
    public ResultBody delete(@PathVariable List<Integer> ids) throws Exception {
        identityAuthService.removeByIds(ids);
        return ResultBody.success();
    }

    @GetMapping("/g")
    public ResultBody page(IdentityAuthVo identityAuthVo) throws Exception {
        Page<IdentityAuth> page=new Page<>();
        assign.assign(identityAuthVo,page,"$current,$size");
        return ResultBody.success(identityAuthService.page(page));
    }

    @PostMapping("/regresidentbatch")
    public ResultBody registerResidentBatch(@RequestBody IdentityAuthVo identityAuthVo ) {
        return ResultBody.success(identityAuthService.registerResidentBatch(identityAuthVo));
    }

    @PutMapping("/auditr")
    public ResultBody auditResidentIdentityAuth(@RequestBody IdentityAuthVo identityAuthVo) throws Exception {
        return ResultBody.success(identityAuthService.auditResidentIdentityAuth(identityAuthVo));
    }

    @PutMapping("/auditd")
    public ResultBody auditDistrictHeadIdentityAuth(@RequestBody IdentityAuthVo identityAuthVo) throws Exception {
        return ResultBody.success(identityAuthService.auditDistrictHeadIdentityAuth(identityAuthVo));
    }

    @PostMapping("/userapply")
    public ResultBody userApplyIdentityAuth(@RequestBody IdentityAuthVo identityAuthVo) throws Exception {
//        IdentityAuth identityAuth=new IdentityAuth();
//        assign.assign(identityAuthVo,identityAuth,"$type,$community");
//        identityAuth.setUid(UserUtils.getCurrentUser().getId());
//        identityAuthService.save(identityAuth);
        return ResultBody.success(identityAuthService.userApplyIdentityAuth(identityAuthVo));
    }

    @GetMapping("/userpersonal")
    public ResultBody personalIdentityAuth() {
        return ResultBody.success(identityAuthService.getPersonalIdentityAuth());
    }

    @GetMapping("/getWithUserNameByPage")
    public ResultBody getWithUserNameByPage(IdentityAuthVo identityAuthVo) throws Exception {
        return ResultBody.success(identityAuthService.getWithUserNameByPage(identityAuthVo));
    }

    @GetMapping("/districtHeadGetWithUserNameByPage")
    public ResultBody districtHeadGetWithUserNameByPage(IdentityAuthVo identityAuthVo) throws Exception {
        return ResultBody.success(identityAuthService.districtHeadGetWithUserNameByPage(identityAuthVo));
    }

    @GetMapping("/search")
    public ResultBody search(IdentityAuthVo identityAuthVo) throws Exception {
        return ResultBody.success(identityAuthService.search(identityAuthVo));
    }
}
